package com.tledu.instrument_log.controller;

import com.tledu.common.annotation.Log;
import com.tledu.common.core.controller.BaseController;
import com.tledu.common.core.domain.AjaxResult;
import com.tledu.common.core.page.TableDataInfo;
import com.tledu.common.enums.BusinessType;
import com.tledu.instrument.domain.InstrumentLog;
import com.tledu.instrument.domain.vo.InstrumentLogVo;
import com.tledu.instrument.service.IInstrumentLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 仪器操作日志Controller
 * 
 * @author ruoyi
 * @date 2024-08-29
 */
@RestController
@RequestMapping("/instrument_log/log")
public class InstrumentLogController extends BaseController
{
    @Autowired
    private IInstrumentLogService instrumentLogService;

    /**
     * 查询仪器操作日志列表
     */
    @PreAuthorize("@ss.hasPermi('instrument_log:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(InstrumentLogVo instrumentLogVo)
    {
        startPage();
        List<InstrumentLogVo> list = instrumentLogService.selectInstrumentLogList(instrumentLogVo);
        return getDataTable(list);
    }

    /**
     * 导出仪器操作日志列表
     */
//    @PreAuthorize("@ss.hasPermi('instrument_log:log:export')")
//    @Log(title = "仪器操作日志", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, InstrumentLog instrumentLog)
//    {
//        List<InstrumentLog> list = instrumentLogService.selectInstrumentLogList(instrumentLog);
//        ExcelUtil<InstrumentLog> util = new ExcelUtil<InstrumentLog>(InstrumentLog.class);
//        util.exportExcel(response, list, "仪器操作日志数据");
//    }

    /**
     * 获取仪器操作日志详细信息
     */
    // 查看按钮
    @PreAuthorize("@ss.hasPermi('instrument_log:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(instrumentLogService.selectInstrumentLogById(id));
    }

    /**
     * 新增仪器操作日志
     */
    @PreAuthorize("@ss.hasPermi('instrument_log:log:add')")
    @Log(title = "仪器操作日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InstrumentLog instrumentLog)
    {
        return toAjax(instrumentLogService.insertInstrumentLog(instrumentLog));
    }

    /**
     * 修改仪器操作日志
     */
    @PreAuthorize("@ss.hasPermi('instrument_log:log:edit')")
    @Log(title = "仪器操作日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InstrumentLog instrumentLog)
    {
        return toAjax(instrumentLogService.updateInstrumentLog(instrumentLog));
    }

    /**
     * 删除仪器操作日志
     */
    @PreAuthorize("@ss.hasPermi('instrument_log:log:remove')")
    @Log(title = "仪器操作日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(instrumentLogService.deleteInstrumentLogByIds(ids));
    }

    // 删除日志表记录
//    @PutMapping("/{id}")
//    public AjaxResult delete(@PathVariable Long id) {
//        return toAjax(instrumentLogService.updateInstrumentStatus(id));
//    }
}
